package com.gepengjun.lims.util;

import java.lang.reflect.Method;

public class TransEntityToPojoUtil {

    public Object trans(Object source,Object target){
        Method[] srcMethods = source.getClass().getMethods();
        Method[] targetMethods = target.getClass().getMethods();
        for (Method sm:srcMethods){
            String srcName = sm.getName();
            if (srcName.startsWith("get")){
                try {
                    Object result = sm.invoke(source);
                    for (Method tm:targetMethods){
                        String tarName = tm.getName();
                        if (tarName.startsWith("set")&& tarName.substring(3,tarName.length()).equals(srcName.substring(3,srcName.length()))){
                            tm.invoke(target,result);
                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        return target;
    }
}
